package servlets;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

public class AreaMysql {

	   Connection conn = null;
       private String schema="udsv1";
       private String user="root"; 
       private String pass="fagoner";
       private String host="localhost";
       
       public Connection connHostDevelopment(){
               try{
                       Class.forName("com.mysql.jdbc.Driver").newInstance();
                       String sql="jdbc:mysql://"+host+"/"+schema+"?user="+user+"&password="+pass;
                       Connection conexion = (Connection) DriverManager.getConnection(sql);
                       return conexion;
               } 
               catch(Throwable e){
                       return null;
               } 
       }
       
       public AreaMysql(){
    	   conn=this.connHostDevelopment();
       }
       
       public boolean Existe(String nomarea){
    	   boolean salida=false;
    	   System.out.println("nomarea: "+nomarea);
    	   try{    
               PreparedStatement stm=(PreparedStatement)conn.prepareStatement("select descripcion from area where nomarea=\""+nomarea+"\"");
                   ResultSet rs=stm.executeQuery();
                    
               if(rs.next()){                       
            	   salida=true;
            	}                   
               rs.close();
               stm.close();
    	   	  }
          
	       catch(Throwable e){
	               System.out.println(""+e.toString());
	       }
               return salida;
       }
       
}
